package jmind.core.stringMatch.ahocorasick;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Iterator;

/**
   Quick and dirty code: measures the amount of time it takes to
   construct an AhoCorasick tree out of all the words in
   <tt>/usr/share/dict/words</tt>.
 */

public class TimeTrial {
    static public void main(String[] args) throws IOException {
        long startTime = System.currentTimeMillis();
        AhoCorasick tree = new AhoCorasick();
        BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(
                "D:/d/workspace/im20/sc-search/data/dic/tags/words-taobaocats.dic")));
        String line;
        while ((line = reader.readLine()) != null) {
            tree.add(line.getBytes(), null);
        }
        tree.prepare();
        String text = "羽绒羊绒羊毛呢涤纶人造棉纯棉粗花呢法兰绒长毛绒仿s呢料";
        Iterator it = tree.search(text.getBytes("UTF-8"));
        while (it.hasNext()) {
            SearchResult next = (SearchResult) it.next();

        }
        long endTime = System.currentTimeMillis();
        System.out.println("endTime - startTime = " + (endTime - startTime) + " milliseconds");
    }
}
